function show_weather()
{
	
	var txt;
	//alert("data.result"+$("#cityname").val());
	$.ajax({
		dataType: 'JSONP',
    url:"http://v.juhe.cn/weather/index?cityname="+$("#cityname").val()+"&dtype=&format=2&key=f4a428cfdfb0c86b2d7cc834d9898d76",
       type:'GET',
	   async:true,
         jsonp:'callback',  
        success:function(result) {  
        var list = $("#weather").get(0);   
            var show = "<table border='3'>";  
			var i;
            show += "<tr><td>城市</td><td>当前温度</td><td>风向</td><td>时间</td></tr>";  
			//alert(result.result.future[2].weather);
           // for(var i=0;i<localStorage.length;i++)
		//	{  
             
                show += "<tr><td>"+result.result.today.city+"</td><td>"+result.result.sk.temp+"</td><td>"+result.result.sk.wind_direction+"</td><td>"+result.result.sk.time+"</td></tr>";  
           // }  
            show += "</table>";  
            //list.innerHTML = show;  
        	$("#weather").after(show);    
        },  
});
}
function show_weather2()
{
	
	var txt;
	//alert("data.result"+$("#cityname").val());
	$.ajax({
		dataType: 'JSONP',
    url:"http://v.juhe.cn/weather/index?cityname="+$("#cityname").val()+"&dtype=&format=2&key=f4a428cfdfb0c86b2d7cc834d9898d76",
       type:'GET',
	   async:true,
         jsonp:'callback',  
        success:function(result) {  
        //var list = $("#future").get(0);   
            var show = "<table border='3'>"; 
			var i; 
            show += "<tr><td>城市</td><td>当前温度</td><td>天气</td><td>风力</td><td>星期</td><td>日期</td></tr>";  
            for(i = 0; i < result.result.future.length; i++)  
           {  
             
                show += "<tr><td>"+result.result.today.city+"</td>";
				show += "<td>"+result.result.future[i].temperature+"</td>";
				show += "<td>"+result.result.future[i].weather+"</td><td>"+result.result.future[i].wind+"</td>";
				show += "<td>"+result.result.future[i].week+"</td><td>"+result.result.future[i].date+"</td></tr>";  
           }    
            show += "</table>";  
            //list.innerHTML = show;  
        	$("#future").after(show);    
        },  
});
}

function validateForm()
{
	var x=$("#email").val();
	var atpos=x.indexOf("@");
	
	var dotpos=x.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
	{
		alert("不是一个有效的 e-mail 地址");
	    return false;
		}
	if ($("#pwd").val()!=$("#pwde").val()||$("#pwd").val()==null)
	{
		alert("两次密码输入不一致");
		return false;
	}
	var search_site =  $("#keyname").text();  
        var siteurl = localStorage.getItem(search_site);  
       if(siteurl!=null)
	   {
		   alert("用户名已使用");
		   return false;
	   }
}
    



 function find(){  
        var search_site = $("#firstname").val();  
        var str = localStorage.getItem(search_site); 
		// var site = JSON.parse(str); 
         // document.write(str.siteurl);
		 if(str==null)
	   {
		   alert("用户名不存在");
		   return false;
	   }
	   
	   var site = JSON.parse(str);
	   
	   if($("#pwd").val()!=site.siteurl)
	   {
		   alert("密码不存在");
		   return false;
	   }
	   sessionStorage.username =search_site;
	   window.location.href='http://ranyuesheng.gitee.io/buptsice_training_2017_2/2~4th_homework/go.html';
 }


        function check()
		{
			var username=sessionStorage.key(sessionStorage.length);
         if(sessionStorage.length==0)
		 {
			 alert("非法访问！");
           // top.location='http://ranyuesheng.gitee.io/buptsice_training_2017_2/loadin.html';
			window.location.href='http://ranyuesheng.gitee.io/buptsice_training_2017_2/2~4th_homework/loadin.html';
			//self.location.href="http://ranyuesheng.gitee.io/buptsice_training_2017_2/loadin.html";
			 
		 }


           else { var list =$("div").get(0);
		 //  alert($("div").get(0)); 
               list.innerHTML =sessionStorage.getItem("username");
			   loadAll();
		   }
		}


	      function loadAll(){  
        var list = $("#list").get(0);  
        if(localStorage.length>0){  
            var result = "<table border='1'>";  
            result += "<tr><td>用户名</td><td>密码</td><td>邮箱</td><td>注册时间</td></tr>";  
            for(var i=0;i<localStorage.length;i++)
			{  
                var sitename = localStorage.key(i);  
                var str = localStorage.getItem(sitename); 
				var site = JSON.parse(str);
                result += "<tr><td>"+sitename+"</td><td>"+site.siteurl+"</td><td>"+site.sitename+"</td><td>"+site.nowtime+"</td></tr>";  
            }  
            result += "</table>";  
            list.innerHTML = result;  
        }else{  
            list.innerHTML = "数据为空……";  
        }  
    }      
	   


function save(){  
    var site = new Object;//用了一下js方法
	//site.name=localStorage.length;
    site.keyname = document.getElementById("keyname").value;
    site.sitename = document.getElementById("email").value;  
    site.siteurl = document.getElementById("pwd").value;
	var d=new Date();
	site.nowtime=d.toLocaleDateString();
    var str = JSON.stringify(site); // 将对象转换为字符串
    localStorage.setItem(site.keyname,str);  
	//window.location.href='http://ranyuesheng.gitee.io/buptsice_training_2017_2/loadin.html';
    alert("注册成功");
	self.location.href="http://ranyuesheng.gitee.io/buptsice_training_2017_2/2~4th_homework/loadin.html";
}

	//CharMode函数  
//测试某个字符是属于哪一类.  
function CharMode(iN){  
if (iN>=48 && iN <=57) //数字  
return 1;  
if (iN>=65 && iN <=90) //大写字母  
return 2;  
if (iN>=97 && iN <=122) //小写  
return 4;  
else  
return 8; //特殊字符  
}  

//bitTotal函数  
//计算出当前密码当中一共有多少种模式  
function bitTotal(num){  
modes=0;  
for (i=0;i<4;i++){  
if (num & 1) modes++;  
num>>>=1;  
}  
return modes;  
}  

//checkStrong函数  
//返回密码的强度级别  

function checkStrong(sPW){  
if (sPW.length<=4)  
return 0; //密码太短  
Modes=0;  
for (i=0;i<sPW.length;i++){  
//测试每一个字符的类别并统计一共有多少种模式.  
Modes|=CharMode(sPW.charCodeAt(i));  
}  

return bitTotal(Modes);  

}  

//pwStrength函数  
//当用户放开键盘或密码输入框失去焦点时,根据不同的级别显示不同的颜色  

function pwStrength(pwd){  
O_color="#eeeeee";  
L_color="#FF0000";  
M_color="#FF9900";  
H_color="#33CC00";  
if (pwd==null||pwd==''){  
Lcolor=Mcolor=Hcolor=O_color;  
}  
else{  
S_level=checkStrong(pwd);  
switch(S_level) {  
case 0:  
Lcolor=Mcolor=Hcolor=O_color;  
case 1:  
Lcolor=L_color;  
Mcolor=Hcolor=O_color;  
break;  
case 2:  
Lcolor=Mcolor=M_color;  
Hcolor=O_color;  
break;  
default:  
Lcolor=Mcolor=Hcolor=H_color;  
}  
}  

document.getElementById("strength_L").style.background=Lcolor;  
document.getElementById("strength_M").style.background=Mcolor;  
document.getElementById("strength_H").style.background=Hcolor;  
return;  
}   